home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 401-425 / disk_403 / rexxhostlib / libstartup.asm < prev    next >
Assembly Source File  |  1992-05-06  |  4KB  |  119 lines

  1. *--------------------------------------------------------------------*
  2. *    Library startup module, not as funky as Jimm's example
  3. *    Aztec code, but (hopefully) okay for Aztec 5.0.
  4. *
  5. *    Note:    Register usage has been rearranged to allow
  6. *        library init call with parameters in registers.
  7. *
  8. *    Based on LibStart.A68 (with some of the bugs taken out),
  9. *    Copyright (C) 1986, 1987 by Manx Software Systems, Inc.
  10. *--------------------------------------------------------------------*
  11.  
  12.     include    'exec/types.i'
  13.     include    'exec/nodes.i'
  14.     include    'exec/resident.i'
  15.  
  16. *--------------------------------------------------------------------*
  17. *    Here we start the code generation.
  18. *--------------------------------------------------------------------*
  19.  
  20.     section    LibCode,code
  21.  
  22. *--------------------------------------------------------------------*
  23. *    Not executable (also does long word alignment).
  24. *--------------------------------------------------------------------*
  25.  
  26.     moveq    #-1,d0            ; Fail if run from Shell
  27.     rts
  28.  
  29. *--------------------------------------------------------------------*
  30. *    Library version, this should match the lib ID string.
  31. *--------------------------------------------------------------------*
  32.  
  33. LIBVERSION    equ    36
  34.  
  35. *--------------------------------------------------------------------*
  36. *    Global symbols (rather in a bunch than sprenkled).
  37. *--------------------------------------------------------------------*
  38.  
  39.     public    _LibRomTag,_LibName,_LibId,_LibInitTab,_LibInit
  40.     public    _LibMain,.begin,_geta4,__H0_org
  41.  
  42. *--------------------------------------------------------------------*
  43. *    The RomTag structure, must be in first hunk.
  44. *--------------------------------------------------------------------*
  45.  
  46. _LibRomTag:
  47.  
  48.     dc.w    RTC_MATCHWORD        ; Tag ID (680x0 ILLEGAL)
  49.  
  50.     dc.l    _LibRomTag        ; Points to beginning of tag
  51.     dc.l    _LibEndTag        ; Points to end of tag
  52.  
  53.     dc.b    RTF_AUTOINIT        ; Auto init library
  54.     dc.b    LIBVERSION        ; Library version
  55.     dc.b    NT_LIBRARY        ; This is a library, not a device
  56.     dc.b    0            ; Priority (leave it zero)
  57.  
  58.     dc.l    _LibName        ; Pointer to lib name
  59.     dc.l    _LibId            ; Pointer to lib ID
  60.     dc.l    _LibInitTab        ; Pointer to library init table
  61.  
  62. _LibEndTag:
  63.  
  64. *--------------------------------------------------------------------*
  65. *    This is supposed to be the lib entry point.
  66. *--------------------------------------------------------------------*
  67.  
  68. .begin                    ; First hunk
  69.  
  70. *--------------------------------------------------------------------*
  71. *    Set up the lib environment and call the main init routine.
  72. *
  73. *    Register usage:    D0 - APTR to library base
  74. *            A0 - BPTR to library segment list
  75. *
  76. *    Main init routine is expected to return the library base
  77. *    in D0 if library is ready to be used.
  78. *--------------------------------------------------------------------*
  79.  
  80. _LibInit:
  81.  
  82.     movem.l    d2-d7/a2-a6,-(sp)    ; Save registers
  83.     bsr    _geta4            ; Get A4
  84.     lea    __H1_end,a1
  85.     lea    __H2_org,a2
  86.     cmp.l    a1,a2            ; Check if BSS and DATA together
  87.     bne    Start            ; No, don't have to clear
  88.     move.w    #((__H2_end-__H2_org)/4)-1,d1
  89.     bmi    Start            ; Skip if no bss
  90.  
  91.     moveq    #0,d2
  92. 1$    move.l    d2,(a1)+        ; Clear out memory
  93.     dbra    d1,1$
  94.  
  95. Start    move.l    A6,_SysBase        ; Put it where we can get it
  96.  
  97.     jsr    _LibMain        ; Call 'C' init routine
  98.  
  99.     movem.l    (sp)+,d2-d7/a2-a6    ; Restore registers
  100.     rts                ; And return
  101.  
  102. *--------------------------------------------------------------------*
  103. *    Set up A4 to point into the middle of the data segment.
  104. *--------------------------------------------------------------------*
  105.  
  106. _geta4:    far    data
  107.     lea    __H1_org+32766,a4
  108.     rts
  109.  
  110. *--------------------------------------------------------------------*
  111. *    Data segment (globals/hunks).
  112. *--------------------------------------------------------------------*
  113.  
  114.     section    LibData,data
  115.  
  116.     public    _SysBase,_DOSBase,__H1_org,__H1_end,__H2_org,__H2_end
  117.  
  118.     end
  119.